Skip to content

fix: unwrap single non-object array items in allOf#23838

Open
RomiRand wants to merge 2 commits into
OpenAPITools:masterfrom
RomiRand:unwrap-single-allOf
Open

fix: unwrap single non-object array items in allOf#23838
RomiRand wants to merge 2 commits into
OpenAPITools:masterfrom
RomiRand:unwrap-single-allOf

Conversation

@RomiRand
Copy link
Copy Markdown

@RomiRand RomiRand commented May 20, 2026

Fixes #23837

This PR unwraps the entry of an allOf composed schema, if it is the only (non-object) item.


Summary by cubic

Normalizes allOf by removing null sub-schemas (setting nullable) and unwrapping a single sub-schema, and fixes array items normalization. Skips simplification when $ref is present. Resolves #23837.

  • New Features

    • Added SIMPLIFY_ALLOF (opt-in) to simplify allOf and clear allOf on primitive/boolean types in OAS 3.0; documented usage in docs/customization.md.
  • Bug Fixes

    • Normalize array items using the normalized schema; updated tests and added a YAML spec covering allOf (including single-schema enums).

Written for commit df3e846. Summary will update on new commits.

Review in cubic

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@jpfinne
Copy link
Copy Markdown
Contributor

jpfinne commented May 20, 2026

@RomiRand could you move the code to the OpenApiNormalizer?

@RomiRand RomiRand force-pushed the unwrap-single-allOf branch from 1a0451d to ffaeff5 Compare May 22, 2026 18:23
@RomiRand
Copy link
Copy Markdown
Author

@RomiRand could you move the code to the OpenApiNormalizer?

@jpfinne Oh sure didn't realize, it's a big project 😅 I gave it a shot, ptal. Gotten bigger than anticipated, thought it makes sense to integrate with the existing oneOf/anyOf handling.. Lmk if a bigger diff like this should be avoided, or if renaming SIMPLIFY_ONEOF_ANYOF is too much of a breaking change

@jpfinne
Copy link
Copy Markdown
Contributor

jpfinne commented May 26, 2026

@RomiRand renaming an existing rule name is not a good idea. SIMPLIFY_ONEOF_ANYOF is also enabled by default, so your normalization is applied by default. Breaking changes should be avoided as much as possible.

Skipping the $ref does not seem necessary for arrays, especially with the default generateAliasAsModel=false. Even if it is true, I don't think inheritance is used.

Is there a unit test for the sample in #23837?
Does your normalization keeps minItems, maxItems...? For example:

components:
  schemas:
    Data:
      type: object
      properties:
        outer:
          type: array
          items:
            allOf:
              - type: array
                minItems: 1
                items:
                  type: string

@RomiRand
Copy link
Copy Markdown
Author

RomiRand commented Jun 4, 2026

@jpfinne I see, I replaced it with a new rule option.

Is there a unit test for the sample in #23837?
Does your normalization keeps minItems, maxItems...? For example:

Yes, these properties are kept by the existing simplifyOneOfAnyOfAllOfWithOnlyOneNonNullSubSchema. However I need to apply the simplification of this method regardless of the flag being set or not, otherwise the root issue would only be fixed when setting it to true.

I also added a unit test for the new simplification - but that's slightly misleading, as the core issue isn't about normalization. Current main wouldn't break that test either. I mainly want to generate valid code that compiles, optimized schemas are secondary. My earlier test of the InlineModelResolver should've worked more as expected.

Skipping the $ref does not seem necessary for arrays, especially with the default generateAliasAsModel=false. Even if it is true, I don't think inheritance is used.

Without it I'm getting a long list of errors when running tests. I'm not sure where and why my processSimplifyAllOf is even called for most of these test cases, but I don't have the capacity to dive deeper into this, I'm sorry. It's starting with these:

ERROR] Failures: 
[ERROR] org.openapitools.codegen.OpenAPINormalizerTest.testOpenAPINormalizerSimplifyOneOfAnyOf31Spec
[ERROR]   Run 1: OpenAPINormalizerTest.testOpenAPINormalizerSimplifyOneOfAnyOf31Spec:1589 expected [null] but found [#/components/schemas/Parent]
[ERROR]   Run 2: OpenAPINormalizerTest.testOpenAPINormalizerSimplifyOneOfAnyOf31Spec:1589 expected [null] but found [#/components/schemas/Parent]
[ERROR]   Run 3: OpenAPINormalizerTest.testOpenAPINormalizerSimplifyOneOfAnyOf31Spec:1589 expected [null] but found [#/components/schemas/Parent]
...

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java">

<violation number="1">
P2: `SIMPLIFY_ALLOF` is not default-enabled after the rule split, causing a default-behavior regression for allOf primitive cleanup</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@@ -41,7 +41,7 @@
import java.util.stream.Collectors;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: SIMPLIFY_ALLOF is not default-enabled after the rule split, causing a default-behavior regression for allOf primitive cleanup

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java, line 236:

<comment>`SIMPLIFY_ALLOF` is not default-enabled after the rule split, causing a default-behavior regression for allOf primitive cleanup</comment>

<file context>
@@ -227,7 +233,7 @@ public OpenAPINormalizer(OpenAPI openAPI, Map<String, String> inputRules) {
 
         // rules that are default to true
-        rules.put(SIMPLIFY_ONEOF_ANYOF_ALLOF, true);
+        rules.put(SIMPLIFY_ONEOF_ANYOF, true);
         rules.put(SIMPLIFY_BOOLEAN_ENUM, true);
         rules.put(SIMPLIFY_ONEOF_ANYOF_ENUM, true);
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] array schemas with single non-object allOf entry aren't resolved

2 participants